package base;

import java.time.LocalDate;

class BorrowRecord {
	private Book book;
    private Reader reader;
    private LocalDate borrowDate;
    private LocalDate returnDate;

    public BorrowRecord(Book book, Reader reader, LocalDate borrowDate) {
        this.book = book;
        this.reader = reader;
        this.borrowDate = borrowDate;
    }

    public Book getBook() { return book; }
    public Reader getReader() { return reader; }
    public LocalDate getBorrowDate() { return borrowDate; }
    public LocalDate getReturnDate() { return returnDate; }
    public void setReturnDate(LocalDate returnDate) { this.returnDate = returnDate; }

    public boolean isReturned() { return returnDate != null; }

    @Override
    public String toString() {
        return String.format("借阅记录：读者=%s(%s), 图书=%s(%s), 借出=%s, 归还=%s",
                reader.getName(), reader.getReaderId(),
                book.getTitle(), book.getIsbn(),
                borrowDate,
                returnDate == null ? "未归还" : returnDate.toString());
    }

    public String toFileString() {
        return String.format("%s,%s,%s,%s,%s",
                reader.getReaderId(),
                reader.getName(),
                book.getIsbn(),
                borrowDate.toString(),
                (returnDate == null ? "" : returnDate.toString()));
    }
}
